/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.user;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.News;
import po.Organization;
import po.User;
import service.UserService;

/**
 *
 * @author sony
 */
public class UserInfoAction extends ActionSupport implements ServletRequestAware{

    private UserService userService;
    private HttpServletRequest request;
    private User user;
    private List<Organization> leadedOrgs;
    private List<Organization> joinedOrgs;

    @Override
    public String execute() {
        String msg;
        int userId;
        if (ActionContext.getContext().getSession().get("user") == null) {
            return ERROR;
        } else {
            userId = Integer.parseInt(request.getParameter("userId"));
            user = userService.getUser(userId);
            if(user==null){
                msg = "user not exist!";
                request.setAttribute("msg", msg);
                return ERROR;
            }else{
                leadedOrgs = (List<Organization>)userService.getOrgLeaded(userId);
                joinedOrgs = (List<Organization>)userService.getOrgJoined(userId);
                return SUCCESS;
            }
        }
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public void setServletRequest(HttpServletRequest arg0) {
        this.request=arg0;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Organization> getJoinedOrgs() {
        return joinedOrgs;
    }

    public void setJoinedOrgs(List<Organization> joinedOrgs) {
        this.joinedOrgs = joinedOrgs;
    }

    public List<Organization> getLeadedOrgs() {
        return leadedOrgs;
    }

    public void setLeadedOrgs(List<Organization> leadedOrgs) {
        this.leadedOrgs = leadedOrgs;
    }

}

